home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18036 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: Please don't shoot me (newbie question)
  5. Date: Thu, 18 Apr 1996 12:29:32 -0400
  6. Organization: Datalytics, Inc
  7. Message-ID: <31766DEC.4EED@datalytics.com>
  8. References: <4l0puc$oa9@interport.net>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Tom Metzger wrote:
  16. > I just started lurking here, so please don't shoot me if this has been asked
  17. > a hundred times before, but....
  18. > Can someone explain to me, in clear terms, what the difference is between
  19. > C and C++  ?  Everytime I've asked someone, the answer is so cryptic, it's
  20. > not funny.
  21.  
  22. C++ is a better C than C.  That, too, is cryptic, I know, but 
  23. let me explain.  C++ offers stricter type checking.  In other 
  24. words, the C++ compiler requires parameters to match functions, 
  25. etc.  C can let more things slide.
  26.  
  27. C++ offers function overloading.  This means that you can have 
  28. more than one function with the same name.  So long as they take 
  29. different parameters, they are different functions.  This means 
  30. you can have several versions of Read or Write, for example, 
  31. that each take different parameters.
  32.  
  33. C++ offers automatic initialization and cleanup of structs (C++ 
  34. classes are structs with private access by default).  
  35. Initialization is done through constructors; cleanup through 
  36. destructors.  When you create a struct (or class object), the 
  37. compiler invokes the corresponding constructor, if any.  When it 
  38. goes out of scope, the compiler invokes the destructor.  This 
  39. allows you to manage various resources (like file handles, heap 
  40. memory allocations, etc.) within the struct (class).
  41.  
  42. C++ offers encapsulation of data and functions.  Functions that 
  43. operate on common data can be encapsulated in a class (or 
  44. struct, if you want).  This makes clear that they class data 
  45. (data members) are shared among those functions, but are not 
  46. (should not be) available to others (except through those 
  47. functions).  This is a powerful thing: it keeps you from 
  48. creating lots of globals that any number of functions can use 
  49. whenever and however they like.  By placing functions that 
  50. operate on the same data in a class (struct) declaration, you 
  51. highlight that they share data among them.  This heightens your 
  52. awareness of their interrelationship.
  53.  
  54. C++ offers many other things, including polymorphism, templates, 
  55. runtime type identification, exceptions, etc.  There is much to 
  56. the C++ beast.
  57.  
  58. -- 
  59. Robert Stewart        | My opinions are usually my own.
  60. Datalytics, Inc.    | stew@datalytics.com
  61.